﻿@using PagedList.Mvc
@model Tippelde.Web.Models.News.NewsListModel

@{
    ViewBag.Title = "Hírek";
}

<div class="row">
    @if (User.Identity.IsAuthenticated)
    {
        <div class="col-md-3">
            <h3>Csoportok</h3>
            <ul class="nav nav-pills nav-stacked">
                <li class='@(ViewBag.SelectedGroupId==null ? "active" : "")'>@Html.ActionLink("Minden hír", "Index", "News")</li>
                @foreach (var g in Model.Groups)
                {
                    <li class='@(ViewBag.SelectedGroupId==g.Id ? "active" : "")'>@Html.ActionLink(g.Name, "Group", "News", new { Id = g.Id }, null)</li>
                }
            </ul>
        </div>
    }
    <div class="@(User.Identity.IsAuthenticated ? "col-md-9" : "col-md-12")">
        <h2>Hírek</h2>
        @Html.ValidationSummary()
        @if (Model.HasAnyEditorRights)
        {
            <p>
                <a href='@Url.Action("Create", "News")' class="btn btn-link" data-remote="@Url.Action("Create", "News", new {partial=true})" data-toggle="modal" data-target="#addNewsModal">
                    <span class="glyphicon glyphicon-plus-sign"></span> Új hír hozzáadása
                </a>

            </p>
        }
        @foreach (var n in Model.News)
        {
            <div class="row">
                <h3>@n.Title</h3>
                <p>@Html.Raw(n.ContentShort)</p>
                <p><i><span class="glyphicon glyphicon-user"></span> <strong>@n.Creator.FullName</strong> (@(n.LastEdited ?? n.AddedAt))</i></p>
                <a href="@Url.Action("Details", "News", new { seoUrl = n.SeoUrl})" class="btn btn-primary">Tovább</a>
                @if (n.IsUserEditor || User.IsInRole("newsmanager"))
                {
                    <a href="@Url.Action("Edit", "News", new { Id = n.Id })"
                       data-remote="@Url.Action("Edit", "News", new { Id = n.Id, partial=true })"
                       data-toggle="modal" data-target="#addNewsModal"
                       class="btn btn-default">Szerkesztés</a>
                    using (Html.BeginForm("Delete", "News", FormMethod.Post, new { @class = "form-action-delete inline-submit-form" }))
                    {
                        @Html.AntiForgeryToken();
                    @Html.Hidden("Id", n.Id);
                    <button type="submit" class="btn btn-danger">
                        Törlés
                    </button>
                    }
                }
            </div>
        }

        <div class="pull-right">
            @Html.PagedListPager(Model.News, page => Url.Action("Index", "News", new { Id = ViewBag.SelectedGroupId, page = page }),
    PagedListRenderOptions.OnlyShowFivePagesAtATime)
        </div>
        <div id="addNewsModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modalTitle" aria-hidden="true">

        </div>
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/tippelde-teameditor")
    <script>
        $(document).ready(function () {
            $('.modal').on('hidden.bs.modal', function () {
                $(this).removeData();
            })
        });
    </script>
}